package com.osmino.contacts.model.contacts;

import java.util.ArrayList;
import java.util.List;

public class ContactProviderFake implements IContactProvider{
	
	private final boolean DBG = true;
	
	List<IContact> list = new ArrayList<IContact>();
	
	public ContactProviderFake(){
		init();
	}
	
	private void init() {
		for(int i = 0;i<100;i++){
			IContactBuilder builder = new ContactBuilderAndroid();
			builder.set(IContact.ID_I, i);
			builder.set(IContact.DISPLAY_NAME_S, "Contact #"+i);
			list.add(builder.create());
		}
	}

	@Override
	public void add(List<IContact> contacts) {
		list.addAll(contacts);
	}

	@Override
	public void modify(List<IContact> contacts) {
		throw new UnsupportedOperationException("modify doesn't work");
	}

	@Override
	public void merge(List<IContact> contacts) {
		throw new UnsupportedOperationException("merge doesn't work");
	}

	@Override
	public void delete(List<IContact> contacts) {
		ArrayList<Integer> ids = new ArrayList<Integer>();
		for(IContact c:contacts){
			int id = c.getData(IContact.ID_I);
			ids.add(id);
		}
		int size = list.size();
		for(int i = size-1;i>=0;i--){
			int id = list.get(i).getData(IContact.ID_I);
			if(ids.contains(id)){
				list.remove(i);
			}
		}
	}

	@Override
	public List<IContact> select() {
		return list;
	}
}